<template>
	<view>
		<u-card :border="false" :head-border-bottom="false" :head-style="headStyle" v-for="(item,index) in storeList"
			:key="index">
			<view class="store" slot="body">
				<view class="image">
					<image :src="src" mode="widthFix"></image>
				</view>
				<view class="content">
					<view class="title">
						{{item.name}}（{{item.introduction}}）
					</view>
					<view class="address">
						{{item.address}}{{item.detailed_address}}
					</view>
				</view>
				<view class="line">

				</view>
				<view class="select" @click="checked(item)">
					选择
				</view>
			</view>
		</u-card>


	</view>
</template>

<script>
	import localhost from '@/config/app.js'
	export default {
		data() {
			return {
				src:'/static/select-store.png',
				headStyle: {
					padding: 0
				},
				page: 1,
				limit: 20,
				loaded: false,
				loading: false,
				storeList: [],
				system_store: {},
				user_latitude: 0,
				user_longitude: 0
			}
		},
		onLoad() {
			this.$u.api.getStore().then(res => {
			if(res.status==200){
				this.storeList=res.data.list
			}
			})
			
		},
		mounted() {
			
		},
		methods: {
			checked(data) {
				uni.setStorageSync('shoeName', {
					shop_id: data.id,
					shopName: data.name
				})
				console.log(data)
				this.$u.route({
					url: 'pages/view_appointment/view_appointment',
					type: 'switchTab'
				})



			},
			selfLocation() {
				let self = this
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						try {
							this.user_latitude = res.latitude;
							this.user_longitude = res.longitude;
							uni.setStorageSync('user_latitude', res.latitude);
							uni.setStorageSync('user_longitude', res.longitude);
						} catch {}
						self.getList();
					},
					complete: function() {
						self.getList();
					}

				})
			},
			// 获取门店列表数据
			getList: function() {
				if (this.loading || this.loaded) return;
				this.loading = true;
				let data = {
					latitude: this.user_latitude || "", //纬度
					longitude: this.user_longitude || "", //经度
					page: this.page,
					limit: this.limit
				};
				storeListApi(data)
					.then(res => {
						this.loading = false;
						this.loaded = res.data.list.length < this.limit;
						this.storeList.push.apply(this.storeList, res.data.list.list);
						this.page = this.page + 1;
						console.log(this.storeList)
					})
					.catch(err => {
						this.$util.Tips({
							title: err
						})
					});
			}
		}
	}
</script>

<style lang="scss">
	.store {
		display: flex;
		justify-content: space-around;
		align-items: center;

		.image {

			width: 50rpx;
			height: 50rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.content {
			width: 60%;
			color: #333333;

			.title {
				font-size: 32rpx;
				font-weight: 700;

			}
		}

		.line {
			height: 100rpx;

			border-right: 2rpx solid #e3e3e3;
		}

		.select {
			color: #eb3626;
		}
	}
</style>
